# !/usr/bin/env python3
# -*- coding:utf-8 -*-
# author: 廖择贵
# createTime: 
# action:

import logging
from config.setting import config


class LoggerHandler(logging.Logger):

    def __init__(self,
                 name='root',
                 level="DEBUG",
                 file=config.log_path,
                 format="%(asctime)s:%(name)s:%(filename)s:%(lineno)s:%(levelname)s:%(message)s",
                 ):
        super().__init__(name)
        # 设置日志级别
        self.setLevel(level)
        # 设置日志输出格式
        fmt = logging.Formatter(format)
        # 初始化处理器
        if file:
            file_handler = logging.FileHandler(file, encoding="utf-8")
            file_handler.setLevel(level)
            file_handler.setFormatter(fmt)
            self.addHandler(file_handler)

        # 输出控制台的日志处理器设置
        stream_handler = logging.StreamHandler()
        stream_handler.setLevel(level)
        stream_handler.setFormatter(fmt)
        self.addHandler(stream_handler)


# if __name__ == "__main__":
#     logger = LoggerHandler()
#     logger.debug("LoggerHandler", "这个是日志")




